package com.lgy.springboot_example.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

@Data
public class OrderDelay implements Delayed, Serializable {

    private Integer id;
    private Long expireTime;

    @Override
    public long getDelay(TimeUnit unit) {
        //此处设置30分钟后订单过期
        return unit.convert(expireTime + 30 * 60 * 1000 - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return (int) (this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
    }
}
